/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package dao;


import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import jaxb.Employers.Employer;
import jaxb.Employers.Employers;
import utils.DBUtils;


/**
 *
 * @author trinhnta
 */
public class EmployerDAO {
    public static Employers getEmployerByUN(String name){
        Connection con = null;
        CallableStatement cal = null;
        ResultSet rs = null;
        try{
            con = DBUtils.makeConnection();
            cal = con.prepareCall("{call getEmployerbyUN(?)}");
            cal.setString(1,name);
            rs = cal.executeQuery();
            Employers emps = new Employers();
            while(rs.next()){
                int id = rs.getInt(1);
                String username = rs.getString(2);
                String address = rs.getString(3);
                String website = rs.getString(4);
                String size = rs.getString(5);
                String companyName = rs.getString(6);
                String companyOverview = rs.getString(7);
                String phone = rs.getString(8);
                String logo = rs.getString(9);
                String banner = rs.getString(10);
                String email = rs.getString(11);

                Employer employer = new Employer();

                employer.setEmployerId(id);
                employer.setUsername(username);
                employer.setAddress(address);
                employer.setWebsite(website);
                employer.setSize(size);
                employer.setCompanyName(companyName);
                employer.setCompanyOverview(companyOverview);
                employer.setPhone(phone);
                employer.setLogo(logo);
                employer.setBanner(banner);
                employer.setEmail(email);
                emps.getEmployer().add(employer);
            }
            return emps;
        }catch(SQLException ex){
            System.out.println(ex.getMessage());
        }finally{
            try{
                if(rs != null){
                    rs.close();
                }
                if(cal != null){
                    cal.close();
                }
                if(con != null){
                    con.close();
                }
            }catch(SQLException ex){
                System.out.println(ex.getMessage());
            }
        }
        return null;
    }

}
